<!--
  ~ Licensed to the Apache Software Foundation (ASF) under one or more
  ~ contributor license agreements.  See the NOTICE file distributed with
  ~ this work for additional information regarding copyright ownership.
  ~ The ASF licenses this file to You under the Apache License, Version 2.0
  ~ (the "License"); you may not use this file except in compliance with
  ~ the License.  You may obtain a copy of the License at
  ~
  ~     http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License.
  -->

<div class="relationship-settings flex gap-y-4">
    <div class="flex basis-1/2 flex-col gap-y-4 pr-4 overflow-hidden">
        <div class="flex flex-col">
            <div class="flex items-center gap-x-1.5">
                <div>Automatically Terminate/Retry Relationships</div>
                <i
                    class="fa fa-info-circle primary-color"
                    nifiTooltip
                    [tooltipComponentType]="TextTip"
                    tooltipInputData="Will automatically terminate and/or retry FlowFiles sent to a given relationship if it is not defined elsewhere. If both terminate and retry are selected, any retry logic will happen first, then auto-termination."></i>
            </div>
            <div class="flex flex-col gap-y-3">
                @for (relationship of relationships; track relationship; let i = $index) {
                    <div class="flex flex-col gap-y-1.5">
                        <div
                            class="tertiary-color font-medium overflow-ellipsis overflow-hidden whitespace-nowrap"
                            [title]="relationship.name">
                            {{ relationship.name }}
                        </div>
                        <div class="flex items-center gap-x-2">
                            <mat-checkbox
                                [(ngModel)]="relationship.autoTerminate"
                                name="autoTerminate-{{ i }}"
                                (change)="handleChanged()"
                                [disabled]="isDisabled"
                                >terminate
                            </mat-checkbox>
                            <mat-checkbox
                                [(ngModel)]="relationship.retry"
                                name="retry-{{ i }}"
                                (change)="handleChanged()"
                                [disabled]="isDisabled"
                                >retry
                            </mat-checkbox>
                        </div>
                        @if (hasDescription(relationship)) {
                            <div class="ml-2">{{ relationship.description }}</div>
                        }
                    </div>
                }
            </div>
        </div>
    </div>
    <div class="flex basis-1/2 flex-col">
        <div class="flex flex-col">
            @if (isRelationshipRetried()) {
                <div>
                    <mat-form-field>
                        <mat-label>
                            Number of Retry Attempts
                            <i
                                class="fa fa-info-circle"
                                nifiTooltip
                                [tooltipComponentType]="TextTip"
                                tooltipInputData="For relationships set to retry, this number indicates how many times a FlowFile will attempt to reprocess before it is routed elsewhere. Must be a non-negative integer."></i>
                        </mat-label>
                        <input
                            matInput
                            [(ngModel)]="retryCount"
                            type="number"
                            min="0"
                            name="retryCount"
                            (keyup)="handleChanged()"
                            [required]="true"
                            [readonly]="isDisabled" />
                    </mat-form-field>
                </div>
                <div class="flex flex-col mb-6">
                    <div class="flex items-center gap-x-1.5">
                        <div>Retry Back Off Policy</div>
                        <i
                            class="fa fa-info-circle primary-color"
                            nifiTooltip
                            [tooltipComponentType]="TextTip"
                            tooltipInputData="Penalize: Retry attempts will occur in time, but the processor will continue to process other FlowFiles. Yield: No other FlowFile processing will occur until all retry attempts have been made."></i>
                    </div>
                    <mat-radio-group
                        [(ngModel)]="backoffMechanism"
                        (change)="handleChanged()"
                        [disabled]="isDisabled"
                        class="flex gap-x-2">
                        <mat-radio-button value="PENALIZE_FLOWFILE">Penalize</mat-radio-button>
                        <mat-radio-button value="YIELD_PROCESSOR">Yield</mat-radio-button>
                    </mat-radio-group>
                </div>
                <div>
                    <mat-form-field>
                        <mat-label>
                            Retry Maximum Back Off Period
                            <i
                                class="fa fa-info-circle"
                                nifiTooltip
                                [tooltipComponentType]="TextTip"
                                tooltipInputData="Initial retries are based on the Penalty/Yield Duration time specified in the Settings tab. The duration time is repeatedly doubled for every subsequent retry attempt. This number indicates the maximum allowable time period before another retry attempt occurs."></i>
                        </mat-label>
                        <input
                            matInput
                            [(ngModel)]="maxBackoffPeriod"
                            type="text"
                            (keyup)="handleChanged()"
                            [required]="true"
                            [readonly]="isDisabled" />
                    </mat-form-field>
                </div>
            }
        </div>
    </div>
</div>
